package ai.engine;

import ai.Comparable;
import ai.engine.factories.FuzzyEngineFactory;

public class PossibleAssignment implements Comparable {

	public Task task;
	public TaskDoer possibleTaskDoer;
	public short score;

	public PossibleAssignment(Task task, TaskDoer possibleTaskDoer) {
		this.task = task;
		this.possibleTaskDoer = possibleTaskDoer;
		setScore();
	}

	private void setScore() {
		short eta = (short) possibleTaskDoer.getETA();
		if (eta == 0 || eta == -1)
			eta = 1;
		this.score = (short) FuzzyEngineFactory.getResAllocFuzzyEngine().defuzzify(task.getFormula(possibleTaskDoer), eta);
	}

	public int compareTo(Object o) {
		return this.score - ((PossibleAssignment) o).score;
	}

	public String toString() {
		return new StringBuffer("- score ")
			.append(score)
			.append("=priority ")
			.append(task.getFormula(possibleTaskDoer))
			.append(" : (")
			.append(task.id)
			.append(") ")
			.append(task.name)
			.append(" ")
			.append(task.target)
			.append(" possibleTaskDoer ")
			.append(possibleTaskDoer)
			.append("\n")
			.toString();
	}

}
